/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package resources.code.classes;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * Web application lifecycle listener.
 * @author rmatos
 */
@WebListener()
public class QuoteContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("QuotesPU");
        EntityManager em = emf.createEntityManager();

        //Index's ComboBox Items
        List<String> names = em.createNamedQuery("TblQuote.findAllName").getResultList();
   
        sce.getServletContext().setAttribute("names", names);

    }

    public void contextDestroyed(ServletContextEvent sce) {
        
    }
}
